﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bussiness;

namespace WebApplication.Admin
{
    public partial class BaoCaoCongNoKH : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadKh();
            }

        }
        public void LoadKh()
        {
            IUnitOfWork iunitfwork = new EFUnitOfWork();
            KHACHHANGRepository repository = new KHACHHANGRepository(new EFRepository<KHACHHANG>(), iunitfwork);
            IQueryable<KHACHHANG> objkhachhang = repository.All();
            Dlkhachhang.DataSource = objkhachhang;
            Dlkhachhang.DataValueField = "MAKH";
            Dlkhachhang.DataTextField = "TENKH";
            Dlkhachhang.DataBind();
            Dlkhachhang.Items.Insert(0, new ListItem {Text="---Chọn khách hàng---",Value="0" });
        }

        protected void lbtnxem_Click(object sender, EventArgs e)
        {
            Microsoft.Reporting.WebForms.ReportDataSource source;
            DateTime dt=DateTime.Now;
            string ngay=dt.ToString("dd/MM/yyyy");
            if (Dlkhachhang.SelectedValue.Equals("0"))
            {

                source = new Microsoft.Reporting.WebForms.ReportDataSource("CongNoKH", new Baocao.BaoCaoCongNoKhTheoNgay().GetCongNoKh(ngay));
                ReportViewer1.LocalReport.ReportPath = @"Admin\Baocao\BaoCaoCongNoKh.rdlc";
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(source);
                ReportViewer1.LocalReport.Refresh();
            }
            else
            {
                string makh = Dlkhachhang.SelectedValue;
                source = new Microsoft.Reporting.WebForms.ReportDataSource("CongNoKH", new Baocao.BaoCaoCongNoKhTheoNgay().GetCongNoKh(ngay,makh));
                ReportViewer1.LocalReport.ReportPath = @"Admin\Baocao\BaoCaoCongNoKh.rdlc";
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(source);
                ReportViewer1.LocalReport.Refresh();
            }
        }
    }
}